﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CRM.UTIL
{
    public class MessageBox
    {
        private MessageBox()
        {
        }

        /// <summary>
        /// 显示消息提示对话框

        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void Show(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
        }

        /// <summary>
        /// 显示消息提示对话框并返回上一页

        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowHistory(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');history.go(-1);</script>");
        }

        /// <summary>
        /// 控件点击 消息确认提示框

        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            //Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        public static void Redirect(System.Web.UI.Page page, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("window.location.href='{0}'", url);
            Builder.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
        }

        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转

        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("window.location.href='{0}'", url);
            Builder.Append("</script>");
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "message", Builder.ToString());

        }
        /// <summary>
        /// 输出自定义脚本信息

        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="script">输出脚本</param>
        public static void ResponseScript(System.Web.UI.Page page, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");

        }

        /// <summary>
        /// 弹出消息并且关闭页面
        /// </summary>
        /// <param name="page"></param>
        /// <param name="message"></param>
        public static void ShowAndClose(System.Web.UI.Page page, string message)
        {
            ResponseScript(page, "alert('" + message + "');window.close();");
        }

        /// <summary>
        /// CRM新工作任务邮件提醒
        /// </summary>
        /// <param name="assignUserName">下达人</param>
        /// <param name="manageUserName">负责人</param>
        /// <param name="taskName">任务名称</param>
        /// <param name="taskid">任务ID</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="createTime">创建时间</param>
        /// <returns></returns>
        public static string GetTaskStartMailBody(string assignUserName, string manageUserName, string taskName, string taskid, string startTime, string endtime, string createTime)
        {
            StringBuilder sb = new StringBuilder("<font style='font-family: 华文细黑;'>尊敬的<font style=\"color:blue;font-weight:bolder\">");
            sb.Append(manageUserName);
            sb.Append("</font>：<br><p style=\"padding:0px 0px 0px 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您好！</p>");
            sb.Append("<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            sb.Append("<font style=\"color:blue;font-weight:bolder\">");
            sb.Append(assignUserName);
            sb.Append("</font>");
            sb.Append("于" + createTime + "给您下达新的工作任务：");
            sb.Append("<a href=\"" + System.Configuration.ConfigurationManager.AppSettings["strMailProcessWebSite"] + "/iTask/MyTask/TaskEdit.aspx?task_id_=" + taskid + "\"");
            sb.Append(" style=\"color:blue;font-weight:bolder\">");
            sb.Append(taskName);

            sb.Append("[<font style=\"color:blue;font-weight:bolder\">" + startTime + "</font>");
            sb.Append("至<font style=\"color:blue;font-weight:bolder\">" + endtime + "</font>]");
            sb.Append("</a>。");
            sb.Append("详情请通过任务链接登录CRM系统查看，谢谢！祝您工作顺利！");
            sb.Append("<p><div style=\"width:100%;text-align:right;padding-right:40px\">沿海集团</div>");
            sb.Append("<div style=\"width:100%;text-align:right;padding-right:25px\">" + System.DateTime.Now + "</div></p></font>");
            return sb.ToString();
        }

        //    /// <summary>
        //    /// 
        //    /// </summary>
        //    /// <param name="meetingHostName">会议主持人</param>
        //    /// <param name="meetingJoinName">参与人员</param>
        //    /// <param name="meetingName"></param>
        //    /// <param name="meetTime"></param>
        //    /// <param name="meetRoom"></param>
        //    /// <param name="meetingTopic"></param>
        //    /// <param name="participantName"></param>
        //    /// <returns></returns>
        //    public static string GetMeetingMailBody(string meetingid, string guid, string meetingHostName, string meetingJoinName, string meetingName, DataTable meetTime, string meetRoom, string meetingTopic, string participantName, string remarking, CRM.UTIL.MeetingMailStatus meetingMailStatus)
        //    {
        //        StringBuilder meetingTimeSb = new StringBuilder();
        //        for (int i = 0; i < meetTime.Rows.Count; i++)
        //        {
        //            //if(!string.IsNullOrEmpty(meetingTimeSb.ToString()))
        //            //{
        //            //  meetingTimeSb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
        //            //}
        //            //DataRow r=meetTime.Rows[i];
        //            //meetingTimeSb.Append(string.Format("{0}  ({1}-{2}) <br/>",Convert.ToDateTime(r["date_"].ToString()).ToString("yyyy-MM-dd"),r["start_time"].ToString(),r["end_time"].ToString()));
        //            DataRow r = meetTime.Rows[i];
        //            if (meetTime.Rows.Count == 1)
        //            {
        //                meetingTimeSb.Append(string.Format("{0} {1}  到  {0} {2}<br/>", Convert.ToDateTime(r["date_"].ToString()).ToString("yyyy-MM-dd"), r["start_time"].ToString(), r["end_time"].ToString()));
        //            }
        //            else if (i == 0)
        //            {
        //                meetingTimeSb.Append(string.Format("{0}  {1}", Convert.ToDateTime(r["date_"].ToString()).ToString("yyyy-MM-dd"), r["start_time"].ToString()));
        //            }
        //            else if (i == meetTime.Rows.Count - 1)
        //            {
        //                meetingTimeSb.Append(string.Format("   到  {0}  {1}<br/>", Convert.ToDateTime(r["date_"].ToString()).ToString("yyyy-MM-dd"), r["end_time"].ToString()));
        //            }
        //        }
        //        StringBuilder sb = new StringBuilder();
        //        int meetingStatus = (int)meetingMailStatus;
        //        if (meetingStatus == (int)MeetingMailStatus.SendMeetingFirst)
        //            sb.Append("<p>您收到[" + meetingHostName + "]发起的会议通知[<font style=\"color:blue;font-weight:200\">");
        //        else if (meetingStatus == (int)MeetingMailStatus.UpdateMeeting)
        //            sb.Append("<p>" + meetingName + "会议已修改[<font style=\"color:blue;font-weight:200\">");
        //        else if (meetingStatus == (int)MeetingMailStatus.CancelMeeting)
        //            sb.Append("<p>" + meetingName + "已取消[<font style=\"color:blue;font-weight:200\">");

        //        sb.Append("<a href=\"" + System.Configuration.ConfigurationManager.AppSettings["strMailProcessWebSite"] + "/Meeting/MeetingView.aspx?id=" + meetingid + "&guid=" + guid + "&isbrower=1\">" + meetingName);
        //        sb.Append("</a></font>],您可以直接点击链接登陆CRM系统了解会议详情,并及时上载相关上会文件,或者登录沿海移动办公平台查阅</p>");

        //        if (meetingStatus == (int)MeetingMailStatus.SendMeetingFirst)
        //            sb.Append("<p><font style=\"font-weight:bolder\">会议事项摘要</font></p>");
        //        else
        //            sb.Append("<p><font style=\"font-weight:bolder\">原会议事项摘要</font></p>");
        //        sb.Append("<font style=\"font-weight:400\">会议标题：</font>" + meetingName + "<br/>");
        //        sb.Append("<font style=\"font-weight:400\">召开时间：</font>" + meetingTimeSb.ToString());
        //        sb.Append("<font style=\"font-weight:400\">会议地点：</font>" + meetRoom + "<br/>");
        //        sb.Append("<font style=\"font-weight:400\">会议主持：</font>" + meetingHostName + "<br/>");
        //        sb.Append("<font style=\"font-weight:400\">与会人员：</font>" + meetingJoinName + "<br/>");
        //        sb.Append("<font style=\"font-weight:400\">抄送对象：</font>" + participantName + "<br/>");
        //        sb.Append("<font style=\"font-weight:400\">会议议程：</font>" + meetingTopic + "<br/>");
        //        //sb.Append("<font style=\"font-weight:400\">会议说明：</font>" + remarking + "<br/>");
        //        sb.Append("<p><div style=\"width:100%;text-align:right;padding-right:40px\">沿海集团</div>");
        //        sb.Append("<div style=\"width:100%;text-align:right;padding-right:25px\">" + System.DateTime.Now + "</div></p></font>");
        //        return sb.ToString();
        //    }


        //    public static string GetMeetingSummaryMailBody(string userName, string fileName, string url)
        //    {
        //        StringBuilder sb = new StringBuilder("<font style='font-family: 华文细黑;'><p><div style=\"width:100%;text-align:center;\"><font style=\"font-weight:bolder;font-size:14pt;\">会议纪要上载知会</font></div></p><br>");
        //        sb.Append("<p style=\"padding:0px 0px 0px 30px\">您好！</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ");
        //        sb.Append("<font style=\"color:blue;font-weight:bolder\">");
        //        sb.Append(userName);
        //        sb.Append("于  <font style=\"color:blue;font-weight:bolder\">" + System.DateTime.Now + "</font>");
        //        sb.Append("上载会议纪要【");
        //        sb.Append("<a href=\"" + url + "\"");
        //        sb.Append(" style=\"color:blue;font-weight:bolder\">");
        //        sb.Append(fileName);
        //        sb.Append("</a>。");
        //        sb.Append("您可以通过链接直接登录CRM系统会议管理平台查看，或者登录沿海移动办公平台查阅，谢谢！祝您工作顺利！");
        //        sb.Append("<p><div style=\"width:100%;text-align:right;padding-right:40px\">沿海集团</div>");
        //        sb.Append("<div style=\"width:100%;text-align:right;padding-right:25px\">" + System.DateTime.Now + "</div></p></font>");
        //        return sb.ToString();

        //    }

       
    }
}
